package com.sunmnet.auto.spring.mvc.variable.impl;

import com.sunmnet.auto.spring.mvc.baen.FieldSturcture;
import com.sunmnet.auto.spring.mvc.baen.TBStructure;
import com.sunmnet.auto.spring.mvc.temp.FileType;
import com.sunmnet.auto.spring.mvc.variable.IVarDeal;

public class IndexJsDatagridCols implements IVarDeal {

	public String excute(FileType type, TBStructure tb) {
		StringBuilder sb = new StringBuilder();
		for (FieldSturcture field : tb.getFields()) {
			if(field.getPropertyName().trim().equalsIgnoreCase("createTime") || 
			   field.getPropertyName().trim().equalsIgnoreCase("modifyTime")){
				continue;
			}
			sb.append("\t{");
			sb.append("field: '").append(field.getPropertyName()).append("', title: '")
				.append(field.getPropertyName()).append("', width: 120, sortable: true");
			if(field.getType() != null && "date".equalsIgnoreCase(field.getType().trim())){
				sb.append(", formatter: function(value,row,index) {").append("\r\n");
				sb.append("\t\t").append("if (sUtils.notNull(value)) {").append("\r\n");
				sb.append("\t\t\t").append("value = value.substring(0,10);").append("\r\n");
				sb.append("\t\t").append("}").append("\r\n");
				sb.append("\t\t").append("return value;").append("\r\n");
				sb.append("\t").append("}");
			}
			sb.append("},\r\n");
		}
		sb.append("noData");
		
		String reStr = sb.toString();
		if (reStr.contains(",\r\nnoData")){
			reStr = reStr.replace(",\r\nnoData", "");
		}
		return reStr;
	}
}
